<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>底层方法 - Layui 文档</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script>;!function(){self!==parent&&(location.href="about:blank")}();</script>
  <link href="/public/layui/v/2.8.6/css/layui.css" rel="stylesheet">
  <link href="/public/static/dist/docs/2.8/css/global.css?v=16" rel="stylesheet">
  <script>
  (function(){if(window.JSON&&window.JSON.parse){var c=document.getElementsByTagName("head"),a=document.createElement("link");try{var b=JSON.parse(localStorage.layui)}catch(d){b={}}"dark"===b.themeMode&&(a.href="//res.sentcss.com/static/dist/docs/2.8/css/layui-theme-dark.css?v=16",a.rel="stylesheet",a.id="layuicss-theme-dark",c[0].appendChild(a))}})();
  </script>
</head>
<body>
<div class="layui-header ws-header ws-bg-light">
  <div class="layui-container">
    <div class="ws-logo">
      <a class="logo" href="../../index.html">
        <img src="/public/static/images/layui/logo.png" alt="layui">
      </a>
    </div>
    <div class="ws-header-assist">
      <div class="layui-form layui-hide-xs ws-search" lay-filter="LAY-ws-header-component"></div>
      <div class="layui-hide-xs ws-notice"></div>
    </div>
    
    <div class="ws-header-menu">
      <ul class="layui-nav layui-bg-gray ws-bg-light" id="LAY_NAV_TOP">
        <li class="layui-nav-item" data-dir="docs">
          <a href="index.html">组件</a> 
        </li>
        <li class="layui-nav-item" data-dir="notes">
          <a href="../../notes/index.html">笔记</a> 
        </li>
        <li class="layui-nav-item layui-hide-xs">
          <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">
            <!--<span class="layui-badge-dot" style="left:0; right: auto; margin: -4px 0 0 5px;"></span>--> 
            生态
          </a>
          <dl class="layui-nav-child layui-nav-child-r" style="margin-right: -21px;">  
            <dd class="layui-hide-sm layui-show-xs" lay-unselect>
              <a href="https://gitee.com/layui/layui/issues" target="_blank" rel="nofollow">社区</a>
              <hr>
            </dd>
            <dd lay-unselect>
              <a href="https://dev.layuion.com/extend/" target="_blank">Layui 第三方扩展组件</a>
            </dd>
            <dd lay-unselect>
              <a href="https://github.com/Sight-wcg/layui-theme-dark" target="_blank" lay-unselect>
                Layui 深色主题 <span>(社区贡献)</span>
              </a>
            </dd>
            <dd lay-unselect>
              <a href="https://gitee.com/layui/layui-vue/" target="_blank" lay-unselect>
                Layui of Vue <span>(他人实现)</span>
              </a>
            </dd>
          </dl>
        </li>
        <li class="layui-nav-item">
          <a href="javascript:;">2.8.6</a>
          <dl class="layui-nav-child layui-nav-child-c">  
            <dd lay-unselect class="layui-this"><a href="../../index.html">2.8.6</a></dd>
            <dd lay-unselect><a href="../../2.7/index.html">2.7.6</a></dd>
          </dl>
        </li>
      </ul>
      <div class="ws-header-more">
        <i class="layui-icon layui-icon-shrink-right"></i>
      </div>
      <div class="ws-header-tool ws-bg-light">
        <div class="layui-form ws-header-theme" lay-filter="header-theme">
          <input type="checkbox" name="theme-mode" id="ID-header-theme-mode" lay-filter="header-theme-mode" lay-skin="switch">
          <div lay-checkbox>
            <i class="layui-icon layui-icon-moon"></i> | 
            <i class="layui-icon layui-icon-light"></i>
          </div>
        </div>
        <div>
          <a href="https://github.com/layui/layui" target="_blank" title="Github">
            <i class="layui-icon layui-icon-github layui-font-20"></i>
          </a>
        </div>
        <div>
          <a href="https://gitee.com/layui/layui" target="_blank" title="Gitee">
            <i class="layui-icon layui-icon-gitee layui-font-20" style="color: #C71D23;"></i>
            <!--<img src="https://gitee.com/static/images/logo-en.svg" width="21">-->
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 让 IE8/9 兼容响应式栅格 -->
<!--[if lt IE 9]>
  <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
  <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
 
<div class="layui-container ws-container">
  
<div class="layui-panel ws-menu">
  <ul class="layui-menu layui-menu-lg ws-docs-menu">
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">基础</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="index.html">
              <span>开始使用</span> 
              <span class="layui-font-12 layui-font-gray">Getting Started</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="base.html">
              <span>底层方法</span>
              <span class="layui-font-12 layui-font-gray">Base Function</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="modules.html">
              <span>模块系统</span>
              <span class="layui-font-12 layui-font-gray">Modules</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="versions.html">
              <span>更新日志</span>
              <span class="layui-font-12 layui-font-gray">Versions</span>
              <span class="layui-badge-dot"></span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">布局</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="layout/index.html">
              <span>框体</span>
              <span class="layui-font-12 layui-font-gray">Layout</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="layout/grid.html">
              <span>栅格</span>
              <span class="layui-font-12 layui-font-gray">Grid</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">通用</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="color/index.html">
              <span>颜色</span>
              <span class="layui-font-12 layui-font-gray">Color</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="button/index.html">
              <span>按钮</span>
              <span class="layui-font-12 layui-font-gray">Button</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="icon/index.html">
              <span>图标</span>
              <span class="layui-font-12 layui-font-gray">Icon</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="anim/index.html">
              <span>动画</span>
              <span class="layui-font-12 layui-font-gray">Anim</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">表单</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="form/index.html">
              <span>表单组件</span>
              <span class="layui-font-12 layui-font-gray">Form</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="form/input.html">
              <span>输入框</span>
              <span class="layui-font-12 layui-font-gray">Input / Textarea</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="form/select.html">
              <span>选择框</span>
              <span class="layui-font-12 layui-font-gray">Select</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="form/checkbox.html">
              <span>复选框</span>
              <span class="layui-font-12 layui-font-gray">Checkbox</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="form/radio.html">
              <span>单选框</span>
              <span class="layui-font-12 layui-font-gray">Radio</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">展示</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="table/index.html">
              <span>表格</span>
              <span class="layui-font-12 layui-font-gray">Table</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="laypage/index.html">
              <span>分页</span>
              <span class="layui-font-12 layui-font-gray">Laypage</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="treeTable/index.html">
              <span>树形表格</span>
              <span class="layui-font-12 layui-font-gray">TreeTable</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="nav/index.html">
              <span>导航菜单</span>
              <span class="layui-font-12 layui-font-gray">Nav</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="menu/index.html">
              <span>基础菜单</span>
              <span class="layui-font-12 layui-font-gray">Menu</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="tab/index.html">
              <span>选项卡</span>
              <span class="layui-font-12 layui-font-gray">Tab</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="badge/index.html">
              <span>徽章</span>
              <span class="layui-font-12 layui-font-gray">Badge</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="auxiliar/index.html">
              <span>辅助</span>
              <span class="layui-font-12 layui-font-gray">Blockquote / Fieldset / hr</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="class/index.html">
              <span>公共类</span>
              <span class="layui-font-12 layui-font-gray">Class</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="panel/index.html">
              <span>面板</span>
              <span class="layui-font-12 layui-font-gray">Panel / Card / Collapse</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="progress/index.html">
              <span>进度条</span>
              <span class="layui-font-12 layui-font-gray">Progress</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="timeline/index.html">
              <span>时间线</span>
              <span class="layui-font-12 layui-font-gray">Timeline</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="fixbar/index.html">
              <span>固定条</span>
              <span class="layui-font-12 layui-font-gray">Fixbar</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="tree/index.html">
              <span>树组件</span>
              <span class="layui-font-12 layui-font-gray">Tree</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="carousel/index.html">
              <span>轮播</span>
              <span class="layui-font-12 layui-font-gray">Carousel</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="flow/index.html">
              <span>流加载</span>
              <span class="layui-font-12 layui-font-gray">Flow</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="code/index.html">
              <span>代码预览组件</span>
              <span class="layui-font-12 layui-font-gray">Code</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">交互</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="layer/index.html">
              <span>弹出层</span>
              <span class="layui-font-12 layui-font-gray">Layer</span>
              <span class="layui-badge-dot layui-bg-green"></span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="laydate/index.html">
              <span>日期与时间选择</span>
              <span class="layui-font-12 layui-font-gray">Laydate</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="upload/index.html">
              <span>上传</span>
              <span class="layui-font-12 layui-font-gray">Upload</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="dropdown/index.html">
              <span>下拉菜单</span>
              <span class="layui-font-12 layui-font-gray">Dropdown</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="colorpicker/index.html">
              <span>颜色选择器</span>
              <span class="layui-font-12 layui-font-gray">Colorpicker</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="transfer/index.html">
              <span>穿梭框</span>
              <span class="layui-font-12 layui-font-gray">Transfer</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="slider/index.html">
              <span>滑块</span>
              <span class="layui-font-12 layui-font-gray">Slider</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="rate/index.html">
              <span>评分</span>
              <span class="layui-font-12 layui-font-gray">Rate</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    <li class="layui-menu-item-group" lay-options="{type: 'group', isAllowSpread: true}">
      <div class="layui-menu-body-title">其他</div>
      <ul>
        <li>
          <div class="layui-menu-body-title">
            <a href="laytpl/index.html">
              <span>模板引擎</span>
              <span class="layui-font-12 layui-font-gray">Laytpl</span>
            </a>
          </div>
        </li>
        <li>
          <div class="layui-menu-body-title">
            <a href="util/index.html">
              <span>工具模块</span>
              <span class="layui-font-12 layui-font-gray">Util</span>
            </a>
          </div>
        </li>
      </ul>
    </li>
    
  </ul>
</div>

  <div class="ws-content">
    <div class="layui-text ws-text" id="WS-text">
      <h1>底层方法</h1>
<blockquote class="layui-elem-quote">
<p>Layui 提供了一系列基础 API，以更好地辅助组件的使用。</p>
</blockquote class="layui-elem-quote">
<h2 id="config" lay-toc="">全局配置</h2>
<p><code>layui.config(options);</code></p>
<p>您可以在 Layui 模块使用之前，采用该方法进行一些全局化的基础配置，其支持的属性如下：</p>
<pre><code class="layui-code">layui.config({
  base: '' // 设定 Layui 扩展模块的所在目录，一般与 extend 方法搭配使用
  version: false, // 用于更新模块缓存，默认 false。若设为 true，即让浏览器不缓存。也可设为一个任意数值
  dir: 'layui/', // layui 基础目录，用于动态导入 src/layui.js 时的内置模块的加载。一般无需设置
  debug: false, // 用于开启调试模式，默认 false。若设为 true，则模块的引入节点会保留在页面
});
</code></pre>
<!--
### 🌕 预设全局对象 <sup>2.6+</sup>
特别地，若你对 `layui.js` 本身进行了动态加载或是其他特殊场景中使用，那么上述 `layui.config()` 所设定的 `dir` 属性会因此失效，此时你可以在动态加载 <code>layui.js</code> 之前预先定义一个我们约定好的全局对象，如：
```
<script>  
var LAYUI_GLOBAL = {
  dir: '/res/layui/' // layui.js 所在目录
};
</script>
```
> 提示：以上 `dir` 属性的目录设定仅针对特殊场景，如是采用 `<script>` 标签正常引入 layui 的，可以无视该操作。
-->
<h2 id="url" lay-toc="">链接解析</h2>
<p><code>var url = layui.url(href);</code></p>
<p>参数 <code>href</code> 可选，默认自动读取当前页面 URL（<code>location.href</code>）。该方法用于将一段 URL 链接中的 <code>pathname、search、hash</code> 等属性进行对象化处理， 以下是对一个 URL 解析后的返回结果：</p>
<pre><code class="layui-code">// 假设当前页面 url 为： https://domain.com/docs/base.html?a=1&amp;c=3#/user/set/id=123/
var url = layui.url();
 
// url 返回结果为：
{
  &quot;pathname&quot;: [&quot;docs&quot;,&quot;base.html&quot;], // 路径
  &quot;search&quot;: {&quot;a&quot;:&quot;1&quot;,&quot;c&quot;:&quot;3&quot;}, // 参数
  &quot;hash&quot;: { // hash 解析
    &quot;path&quot;: [&quot;user&quot;,&quot;set&quot;,&quot;&quot;], // hash 中的路径
    &quot;search&quot;: {&quot;id&quot;:&quot;123&quot;}, // hash 中的参数
    &quot;hash&quot;: &quot;&quot;,  // hash 中的 hash
    &quot;href&quot;: &quot;/user/set/id=123/&quot;  // hash 中的完整链接
  }
}
</code></pre>
<p>该方法通常可搭配 <code>location.hash</code> 和 <code>hashchange </code> 事件，或 <code>history.pushState()</code> 和 <code>popstate</code> 事件使用，从而实现<em class="layui-text-em">单页面应用开发</em>。 Layui 的 AdminUI 主题模板则正是基于该方法完成的路由系统。</p>
<h2 id="data" lay-toc="">本地存储</h2>
<p>本地存储是对 localStorage 和 sessionStorage 的友好封装，可更方便地管理本地数据。方法如下：</p>
<ul>
<li><code>layui.data(table, settings);</code> 即 localStorage，数据在浏览器中的持久化存储，除非物理删除。</li>
<li><code>layui.sessionData(table, settings);</code> 即 sessionStorage ，数据在浏览器中的会话性存储，页面关闭后即失效。</li>
</ul>
<p>两者使用方式完全一致。其中参数 <code>table</code> 为表名，<code>settings</code> 是一个对象，用于设置 <code>key/value</code>。下面以 <code>layui.data()</code> 方法为例：</p>
<pre><code class="layui-code">// 【增】：向 test 表插入一个 nickname 字段，如果该表不存在，则自动建立。
layui.data('test', {
  key: 'nickname',
  value: '张三'
});
 
// 【删】：删除 test 表的 nickname 字段
layui.data('test', {
  key: 'nickname',
  remove: true
});
layui.data('test', null); // 删除 test 表
  
// 【改】：同【增】，会覆盖已经存储的数据
  
// 【查】：向 test 表读取全部的数据
var localTest = layui.data('test');
console.log(localTest.nickname); // 获得“张三”
</code></pre>
<h2 id="device" lay-toc="">浏览器信息</h2>
<p><code>var device = layui.device(key);</code></p>
<p>参数 <code>key</code> 可选。可利用该方法对不同的设备进行差异化处理，<code>device</code> 即为不同设备下返回的不同信息，如下：</p>
<pre><code class="layui-code">{
  os: &quot;windows&quot;, // 当前浏览器所在的底层操作系统，如：Windows、Linux、Mac 等
  ie: false, // 当前浏览器是否为 ie6-11 的版本，如果不是 ie 浏览器，则为 false
  weixin: false, // 当前浏览器是否为微信 App 环境
  android: false, // 当前浏览器是否为安卓系统环境
  ios: false, // 当前浏览器是否为 IOS 系统环境
  mobile: false // 当前浏览器是否为移动设备环境（v2.5.7 新增）
}
</code></pre>
<p>有时，你的 App 可能会对 userAgent 插入一段特定标识，如：</p>
<pre><code class="layui-code">Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 MYAPP/1.8.6 Safari/537.36
</code></pre>
<p>要验证当前页面是否在你的 App 环境中，即可通过上述 <code>MYAPP</code>（即 Native 给 Webview 插入的标识，可自由定义）来判断。</p>
<pre><code class="layui-code">var device = layui.device('MYAPP');
if(device.MYAPP){
  alert('在 MYAPP 环境中');
}
</code></pre>
<h2 id="api" lay-toc="{hot: true}">API 列表</span></h2>
<p>前面我们特别介绍了几个相对特殊的基础方法，而以下是 Layui 提供的全部基础 API：</p>
<table class="layui-table">
<thead>
<tr>
<th>API</th>
<th>描述</th>
</tr>
</thead>
<tbody>
<tr>
<td>layui.cache</td>
<td>获得 UI 的一些配置及临时缓存信息</td>
</tr>
<tr>
<td>layui.config(options)</td>
<td>基础配置。<a href="base.html#config">#用法</a></td>
</tr>
<tr>
<td>layui.define([modules], callback)</td>
<td>定义模块。<a href="modules.html#define">#用法</a></td>
</tr>
<tr>
<td>layui.use([modules], callback)</td>
<td>加载模块。<a href="modules.html#use">#用法</a></td>
</tr>
<tr>
<td>layui.extend(obj)</td>
<td>扩展模块。<a href="modules.html#extend">#用法</a></td>
</tr>
<tr>
<td>layui.disuse([modules]) <sup>2.7+</sup></td>
<td>弃用模块，以便重新扩展新的同名模块。参数支持数组，即可同时弃用多个模块。 如：<code>layui.disuse(['table'])</code></td>
</tr>
<tr>
<td>layui.link(href)</td>
<td>加载 CSS，<code>href</code> 即为 css 路径。一般用于动态加载你的外部 CSS 文件</td>
</tr>
<tr>
<td>layui.getStyle(node, name)</td>
<td>获得一个原始 DOM 节点的 style 属性值，如： <br><code>layui.getStyle(document.body, 'font-size')</code></td>
</tr>
<tr>
<td>layui.img(src, callback, error)</td>
<td>图片预加载</td>
</tr>
<tr>
<td>layui.each(obj, callback)</td>
<td>对象（Array、Object、DOM 对象等）遍历，可用于取代 for 语句</td>
</tr>
<tr>
<td>layui.type(operand) <sup>2.6.7+</sup></td>
<td>获取基本数据类型和各类常见引用类型，如： <br> <code>layui.type([]); // array</code> <br> <code>layui.type({}); //object</code> <br> <code>layui.type(new Date()); // date</code></td>
</tr>
<tr>
<td>layui.isArray(obj) <sup>2.7+</sup></td>
<td>对象是否为泛数组结构。如 Array、NodeList、jQuery 对象等<br> <code>layui.isArray([1,6]); // true</code> <br> <code>layui.isArray($('div')); // true</code></td>
</tr>
<tr>
<td>layui.sort(obj, key, desc)</td>
<td>将数组中的对象按某个成员重新对该数组排序，如：<code>layui.sort([{a: 3},{a: 1},{a: 5}], 'a');  // 返回：[{&quot;a&quot;:1},{&quot;a&quot;:3},{&quot;a&quot;:5}]</code></td>
</tr>
<tr>
<td>layui.url(href)</td>
<td>链接解析。<a href="base.html#url">#用法</a></td>
</tr>
<tr>
<td>layui.data(table, settings)</td>
<td>持久化存储。<a href="base.html#data">#用法</a></td>
</tr>
<tr>
<td>layui.sessionData(table, settings)</td>
<td>会话性存储。<a href="base.html#data">#用法</a></td>
</tr>
<tr>
<td>layui.device(key)</td>
<td>获取浏览器信息。<a href="base.html#device">#用法</a></td>
</tr>
<tr>
<td>layui.hint()</td>
<td>向控制台打印一些异常信息，目前只返回了 error 方法，如： <br><code>var hint = layui.hint();</code> <br> <code>hint.error('出错啦');</code></td>
</tr>
<tr>
<td>layui.stope(e)</td>
<td>阻止事件冒泡</td>
</tr>
<tr>
<td>layui.onevent(modName, events, callback)</td>
<td>增加自定义模块事件，一般在内置组件中使用。</td>
</tr>
<tr>
<td>layui.event(modName, events, params)</td>
<td>执行自定义模块事件，搭配 onevent 使用。注<sup>2.8+</sup>：当 events 参数中未设定 filter 时则可重复执行该事件，否则只会执行一次最新添加的事件。</td>
</tr>
<tr>
<td>layui.off(events, modName) <sup>2.5.7+</sup></td>
<td>用于移除模块相关事件，如：<code>layui.off('select(filter)', 'form')</code>，那么<code>form.on('select(filter)', callback)</code>事件将会被移除</td>
</tr>
<tr>
<td>layui.debounce(fn, wait) <sup>2.8.3+</sup></td>
<td>防抖，函数按指定毫秒延时执行</td>
</tr>
<tr>
<td>layui.throttle(fn, wait) <sup>2.8.3+</sup></td>
<td>节流，限制函数在指定毫秒内不重复执行</td>
</tr>
<tr>
<td>layui.factory(modName)</td>
<td>用于获取模块对应的 <code>layui.define()</code> 的回调函数</td>
</tr>
<tr>
<td>var lay = layui.lay</td>
<td>基础模块，提供了更多基础 API，一般供 Layui 内置组件中使用</td>
</tr>
</tbody>
</table class="layui-table">
<blockquote class="layui-elem-quote">
<p>基础 API 是整个 UI 的有力支撑，我们在组件的使用过程中也经常会用到。</p>
</blockquote class="layui-elem-quote">

    </div>
    <div class="ws-text-tools">
      
      <a href="https://github.com/layui/layui/edit/2.x/docs/base.md" rel="nofollow" target="_blank" title="在 Github 上编辑此文档">
        <i class="layui-icon layui-icon-edit"></i>
      </a>
      
    </div>
  </div>
</div>
<div class="ws-menu-bar layui-bg-green layui-hide">
  <i class="layui-icon layui-icon-spread-left"></i>
</div>
  
<div class="layui-footer ws-footer">
  <p>
    Copyright &copy; 2023 <a href="../../index.html">Layui</a> MIT Licensed</p>
  <p id="LAY-footer-info">
    <a href="https://gitee.com/layui/layui/blob/main/DISCLAIMER.md" rel="nofollow" target="_blank">免责声明</a> 
    <a href="https://github.com/layui/layui/blob/main/LICENSE" rel="nofollow" target="_blank">开源协议</a>
    <a href="https://gitee.com/layui/" target="_blank">开源生态</a>
    <a href="https://codepen.io/layui/pen/bGxZXrd" rel="nofollow" target="_blank">在线测试</a>
    <a href="https://gitee.com/layui/layui/issues" rel="nofollow" target="_blank">社区交流</a>
  </p>
  <p>
    <span>
      鸣谢：
      <a href="https://www.upyun.com/?invite=SJ0wu6g2-&referer=layui" target="_blank" sponsor="upyun" style="color: #23A7E8;">
        <strong>又拍云</strong>
      </a>
      <a href="https://gitee.com/?referer=layui" target="_blank" sponsor="Gitee" style="color:#C71D23;">
        <strong>Gitee</strong>
      </a>
      <a href="https://www.iconfont.cn/?referer=layui" target="_blank" sponsor="Gitee" style="color: #9B16FF;">
        <strong>iconfont</strong>
      </a>
    </span>
  </p>
</div>
<div class="ws-shade"></div>
 
<script src="/public/layui/v/2.8.6/layui.js"></script>
<script>
layui.config({
  base: '//res.sentcss.com/static/dist/docs/2.8/modules/',
  version: '16',
  res: '//res.sentcss.com/static/dist/docs/',
  curl: ''
}).use('global',function(w){w.a||w.r&&w.r()});
</script>
 
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?363b2abe8678eec8a6850500ea63a63b";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</body>
</html>